package com.js.rtu.config;


import com.js.rtu.util.ToastUtil;

/**
 * 表三、终端通信接口参数设置表
 * 采样周期,单位为秒，范围为 0-65535 秒，其中 0 则代表被动接收
 * Created by wz on 2020/6/19.
 */
public class SamplingPeriodConfig {
    private static final int TYPE_0 = 0;
    private static final String Sampling_Period_0 = "被动接收";
    private static final String Sampling_Period_Err = "数据不在0-65535范围";
    private static final String Sampling_Period_Unite = "秒";

    /**
     * 持续供电时间
     *
     * @param data 数据
     * @return 时间
     */
    public static String getTime(int data) {
        String model = "";
        if (data >= 0 && data <= 65535) {
            if (data == TYPE_0) {
                model = Sampling_Period_0;
            } else {
                model = data + Sampling_Period_Unite;
            }
        } else {
            model = Sampling_Period_Err;
        }

        return model;
    }

    /**
     * 检查是否在0-255范围
     */
    public static boolean checkTime(int time,boolean isShowTips) {
        if (time >= 0 && time <= 65535) {
            return true;
        }
        if (isShowTips){
            ToastUtil.error(Sampling_Period_Err);
        }
        return false;
    }


}



